﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Pixysoft.Framework.Reports.Core
{
    class ReportComponent : IReportComponent
    {
        string componentCode;
        int fontsize = 9;
        string text;

        public string ComponentCode
        {
            get { return componentCode; }
            set { componentCode = value; }
        }
        public int FontSize
        {
            get { return fontsize; }
            set { fontsize = value; }
        }

        public string Text
        {
            get { return text; }
            set { text = value; }
        }
    }

    class ReportComponentCollection : IReportComponentCollection
    {
        List<ReportComponent> texts;

        public ReportComponentCollection(List<ReportComponent> texts)
        {
            this.texts = texts;
        }


        public IReportComponent Create(string text, int fontsize)
        {
            ReportComponent component = new ReportComponent();
            component.ComponentCode = StringHelper.GetComponentCode();
            component.Text = text;
            component.FontSize = fontsize;
            texts.Add(component);
            return component;
        }

        public IReportComponent this[string componentCode]
        {
            get
            {
                foreach (ReportComponent component in texts)
                    if (string.Equals(component.ComponentCode, componentCode))
                        return component;

                return null;
            }
        }

        public IReportComponent Remove(string componentCode)
        {
            IReportComponent component = this[componentCode];

            if (component == null)
                return component;

            Remove(component);

            return component;
        }

        public void Remove(IReportComponent component)
        {
            RemoveReportComponent(component as ReportComponent);
        }

        private void RemoveReportComponent(ReportComponent component)
        {
            if (texts.Contains(component))
                texts.Remove(component);
        }

        public void RemoveAll()
        {
            texts.Clear();
        }
    }
}
